package com.sky.cdutDept.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sky.common.annotation.Log;
import com.sky.common.core.controller.BaseController;
import com.sky.common.core.domain.AjaxResult;
import com.sky.common.enums.BusinessType;
import com.sky.cdutDept.domain.Dept;
import com.sky.cdutDept.service.IDeptService;
import com.sky.common.utils.poi.ExcelUtil;

/**
 * 成都大学部门Controller
 * 
 * @author cjy
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/cdutDept/dept")
public class DeptController extends BaseController
{
    @Autowired
    private IDeptService deptService;

    /**
     * 查询成都大学部门列表
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:list')")
    @GetMapping("/list")
    public AjaxResult list(Dept dept)
    {
        List<Dept> list = deptService.selectDeptList(dept);
        return success(list);
    }

    /**
     * 导出成都大学部门列表
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:export')")
    @Log(title = "成都大学部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dept dept)
    {
        List<Dept> list = deptService.selectDeptList(dept);
        ExcelUtil<Dept> util = new ExcelUtil<Dept>(Dept.class);
        util.exportExcel(response, list, "成都大学部门数据");
    }

    /**
     * 获取成都大学部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return success(deptService.selectDeptByDeptId(deptId));
    }

    /**
     * 新增成都大学部门
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:add')")
    @Log(title = "成都大学部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dept dept)
    {
        return toAjax(deptService.insertDept(dept));
    }

    /**
     * 修改成都大学部门
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:edit')")
    @Log(title = "成都大学部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dept dept)
    {
        return toAjax(deptService.updateDept(dept));
    }

    /**
     * 删除成都大学部门
     */
    @PreAuthorize("@ss.hasPermi('cdutDept:dept:remove')")
    @Log(title = "成都大学部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(deptService.deleteDeptByDeptIds(deptIds));
    }

    /**
     * 查询所有上级部门
     */
    @GetMapping("/parent")
    public AjaxResult selectAllAncestors(String deptName)
    {
    	return success(deptService.selectAllAncestors(deptName));
    }

    /**
     * 查询所有子部门
     */
    @GetMapping("/children")
    public AjaxResult selectAllChildren(String deptName)
    {
    	return success(deptService.selectAllChildren(deptName));
    }

}
